﻿
//***********************************************************************
// * Module:   TbBstDirectorLetterHandler
// * 作者:  曹荣芝
// * Modified: 2013/5/7
// * Purpose: Definition of the Class TbBstDirectorLetterHandler 业务逻辑处理Handler类
// ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XWG.Framework.MSException;
using XWG.Framework.AuthUtility;
using XWG.Framework.AuthEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthBLL;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTSPConst;
using System.Web.Script.Serialization;
using System.Data;
using XWG.Framework.Query;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XWG.JWBST.JWBSTBLL;
using XWG.Framework;
using XWG.Framework.IAuthority;
using System.Collections;
using JWBSTAPP.CommonClass;
using JWBST.CommonClass;
namespace JWBSTAPP.AjaxServer
{
    /// <summary>
    /// TbBstDirectorLetterHandler 的摘要说明
    /// </summary>
    public class TbBstDirectorLetterHandler : JWBSTAPP.CommonClass.HttpHandlerBase, System.Web.SessionState.IRequiresSessionState
    {
        TbMsjwSqjg Rems = new TbMsjwSqjg();
        #region 添加记录
        /// <summary>
        /// 添加记录
        /// </summary>
        protected void AddRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            try
            {
                TbBstDirectorLetter mTbBstDirectorLetter = new TbBstDirectorLetter();
                mTbBstDirectorLetter.Id = Guid.NewGuid().ToString(); //主键
                mTbBstDirectorLetter.Lsh = XWG.JWBST.JWBSTBLL.TbBstFastprocessBLL.GetLSH("TB_BST_DIRECTOR_LETTER");
                mTbBstDirectorLetter.Name = DES.Encode(context.Request.Form["texName"]); //姓名
                mTbBstDirectorLetter.Phone = DES.Encode(context.Request.Form["texPhone"]); //手机
                mTbBstDirectorLetter.Email = DES.Encode(context.Request.Form["texEmail"]); //邮箱
                mTbBstDirectorLetter.Address = DES.Encode(context.Request.Form["texAddress"]); //地址
                mTbBstDirectorLetter.Content = context.Request.Form["texContent"]; //内容
                mTbBstDirectorLetter.Createdate = DateTime.Now; //添加时间
                mTbBstDirectorLetter.Deltag = 0; //删除标志
                mTbBstDirectorLetter.Movesign = "0"; //
                mTbBstDirectorLetter.Replysign = "0";
                mTbBstDirectorLetter.Isview = "0";
                mTbBstDirectorLetter.Tabletype = "2";

                mResultModel = TbBstDirectorLetterBLL.Insert(mTbBstDirectorLetter, context.Session["UserID"], true); //新建操作
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 删除记录
        /// <summary>
        /// 删除记录
        /// </summary>
        protected void DeleteRecord()
        {

            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            try
            {
                string[] arryParamKey = context.Request.Params["id"].ToString().Split(',');
                if (arryParamKey.Length == 0)
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                TbBstDirectorLetter mTbBstDirectorLetter = new TbBstDirectorLetter();
                foreach (var paramKey in arryParamKey)
                {
                    mResultModel = TbBstDirectorLetterBLL.Delete(paramKey, context.Session["UserID"], true); //删除对应的信息
                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); ; //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, ""); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }

        }
        #endregion

        #region 修改记录
        /// <summary>
        /// 修改记录
        /// </summary>
        protected void EditRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            TbBstDirectorLetter mTbBstDirectorLetter = new TbBstDirectorLetter();

            string paramKey = context.Request.Params["id"];
            try
            {

                if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                mTbBstDirectorLetter = TbBstDirectorLetterBLL.Load(paramKey); //根据键值获取实体信息
                if (mTbBstDirectorLetter != null)
                {
                    mTbBstDirectorLetter.Name = DES.Encode(context.Request.Form["texName"]); //姓名
                    mTbBstDirectorLetter.Phone = DES.Encode(context.Request.Form["texPhone"]); //手机
                    mTbBstDirectorLetter.Email = DES.Encode(context.Request.Form["texEmail"]); //邮箱
                    mTbBstDirectorLetter.Address = DES.Encode(context.Request.Form["texAddress"]); //地址
                    mTbBstDirectorLetter.Content = context.Request.Form["texContent"]; //内容
                    mTbBstDirectorLetter.Modifydate = DateTime.Now; //修改时间

                    mResultModel = TbBstDirectorLetterBLL.Update(mTbBstDirectorLetter, context.Session["UserID"], true); //新建操作
                }
                else
                {
                    mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                    mResultModel.ISSucceed = false;

                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 获取实体记录
        /// <summary>
        /// 获取实体记录
        /// </summary>
        protected void GetModel()
        {
            var replyContent = "";
            var replyName = "";
            var replyTime = "";
            QueryByPage Q = new QueryByPage();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            TbMsjwSqjg mTbMsjwSqjg = new TbMsjwSqjg();
            TbBstDic mTbBstDic = new TbBstDic();
            string paramKey = context.Request.Params["id"];
            string json = "";
            try
            {
                TbBstDirectorLetter mTbBstDirectorLetter = new TbBstDirectorLetter(); //声明实体
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mTbBstDirectorLetter = TbBstDirectorLetterBLL.Load(paramKey); //根据键值获取管理员
                    if (mTbBstDirectorLetter != null)
                    {
                        if (mTbBstDirectorLetter.Isview == "0")
                        {
                            mTbBstDirectorLetter.Viewtimestr = "尚未查看";
                        }
                        else
                        {
                            mTbBstDirectorLetter.Viewtimestr = mTbBstDirectorLetter.Viewtime.ToString();
                        }

                        if (mTbBstDirectorLetter.Modifydate.ToString("yyyy") == "0001")
                        {
                            mTbBstDirectorLetter.Modifydatestr = "暂无修改";
                        }
                        else
                        {
                            mTbBstDirectorLetter.Modifydatestr = mTbBstDirectorLetter.Modifydate.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        ////数据库部分加密字段解密
                        mTbBstDirectorLetter.Name = DES.Decode(mTbBstDirectorLetter.Name);
                        mTbBstDirectorLetter.Phone = DES.Decode(mTbBstDirectorLetter.Phone);
                        mTbBstDirectorLetter.Address = DES.Decode(mTbBstDirectorLetter.Address);
                        mTbBstDirectorLetter.Email = DES.Decode(mTbBstDirectorLetter.Email);
                        #region 根据id取回复时间、回复人 回复内容
                        var guid = mTbBstDirectorLetter.Id;
                        try
                        {
                            //DataSet dt = Q.GetRecordByPage("*", " where gdid='" + guid + "' ", "", 1, 1, "tb_msjw_sqjg", "id", "");
                            //if (dt.Tables[0].Rows.Count > 0)
                            //{

                            //    replyContent = dt.Tables[0].Rows[0]["ZB_BLJG"].ToString();
                            //    replyName = dt.Tables[0].Rows[0]["ZB_BLRXM"].ToString();
                            //    replyTime = dt.Tables[0].Rows[0]["ZB_BLRQ"].ToString();
                            //    mTbBstDirectorLetter.Replycontent = replyContent.FilteEnter();
                            //    mTbBstDirectorLetter.Replyname = replyName;
                            //    mTbBstDirectorLetter.Replytime = replyTime;
                            //}
                            var list = TbMsjwSqjgBLL.SelectList(guid);
                            var model = new TbMsjwSqjg();
                            if (list.Count > 0)
                            {
                                if (list.Count == 1)
                                {
                                    model = list.SingleOrDefault();
                                }
                                else if (list.Count > 1)
                                {
                                    var count = list.Where(a => a.Id > 0).Count();
                                    if (count > 0)
                                    {
                                        model = list.FirstOrDefault(a => a.Id > 0);
                                    }
                                    else
                                    {
                                        model = list.OrderByDescending(a => a.ZbBlrq).FirstOrDefault();
                                    }
                                }
                                if (string.IsNullOrEmpty(model.ZbBljg))
                                {
                                    replyContent = "";
                                }
                                else
                                {
                                    replyContent = model.ZbBljg.ToString();
                                }
                                if (string.IsNullOrEmpty(model.ZbBlrxm))
                                {
                                    replyName = "";
                                }
                                else
                                {
                                    replyName = model.ZbBlrxm.ToString();
                                }
                                if (model.ZbBlrq.ToString() == "0001/1/1 0:00:00")
                                {
                                    replyTime = "";
                                }
                                else
                                {
                                    replyTime = model.ZbBlrq.ToString();
                                }
                               
                                mTbBstDirectorLetter.Replycontent = replyContent.FilteEnter();
                                mTbBstDirectorLetter.Replyname = replyName;
                                mTbBstDirectorLetter.Replytime = replyTime;
                            }
                        }
                        catch (Exception e) { }
                        #endregion
                        IsoDateTimeConverter dtConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
                        json = JsonConvert.SerializeObject(mTbBstDirectorLetter, dtConverter);
                        //是否查看
                        if (!String.IsNullOrEmpty(mTbBstDirectorLetter.Isview))
                        {
                            var list = TbBstDicBLL.GetDicByCodeAndParentnode(mTbBstDirectorLetter.Isview, "bool");
                            mTbBstDic = list.FirstOrDefault();
                            Hashtable hashtable = new Hashtable();
                            if (mTbBstDic != null)
                            {
                                hashtable.Add("VIsview", mTbBstDic.Description);
                                json = JsonString.AddAttribute(json, hashtable);
                            }
                        }
                        #region 取回复表的回复内容
                        if (mTbMsjwSqjg != null)
                        {
                            Hashtable hashtable = new Hashtable();
                            hashtable.Add("ZbBljg", mTbBstDirectorLetter.Replycontent);
                            json = JsonString.AddAttribute(json, hashtable);
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9990;
                mResultModel.ISSucceed = false;
                json = JsonConvert.SerializeObject(mResultModel);
            }
            context.Response.Write(json);
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 获取数据记录
        /// </summary>
        protected void QueryRecord()
        {
            TableMessage tm = new TableMessage();
            HearderMessage hm = new HearderMessage();
            List<HearderMessage> list = new List<HearderMessage>();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            string pageSize = context.Request.Form["pageSize"];
            string pageIndex = context.Request.Form["pageIndex"];
            string phone = DES.Encode(context.Request.Form["texPhone"]);////手机号
            string name = DES.Encode(context.Request.Form["TexName"]);////姓名
            string reply = context.Request.Form["selReply"];
            string timeStart = context.Request.Form["texTimeStart"]; ////添加时间-开始
            string timeEnd = context.Request.Form["texTimeEnd"]; ////添加时间-结束
            string LSH = context.Request.Form["TexLSH"];
            if (String.IsNullOrEmpty(pageSize) || String.IsNullOrEmpty(pageIndex) || !AnyString.IsNumeric(pageSize) || !AnyString.IsNumeric(pageIndex))
                return;
            DataTable dtTbBstDirectorLetter = new DataTable();
            int intPageSize = Convert.ToInt32(pageSize);
            int intPageIndex = Convert.ToInt32(pageIndex);
            QueryByPage Q = new QueryByPage();
            SqlConditionList sqllist = new SqlConditionList();
            string sqlWhere = " deltag=0 ";
            if (!string.IsNullOrEmpty(name)) ////姓名
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, TbBstDirectorLetterConst.Columns.Name, name), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(phone)) ////手机号
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, TbBstDirectorLetterConst.Columns.Phone, phone), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(reply)) ////回复状态
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, TbBstDirectorLetterConst.Columns.Replysign, reply), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(LSH)) ////回复状态
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, TbBstDirectorLetterConst.Columns.Lsh, LSH), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(timeStart)) ////添加时间-开始
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.NOT_LESS_THAN, TbBstDirectorLetterConst.Columns.Createdate, Convert.ToDateTime(timeStart)), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(timeEnd)) ////添加时间-结束
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.NOT_MORE_THAN, TbBstDirectorLetterConst.Columns.Createdate, Convert.ToDateTime(timeEnd)), SqlLogicOper.AND_LOGIC);
            }

            if (string.IsNullOrEmpty(sqllist.ToSql()))
            {
                sqlWhere = "where" + sqlWhere;
            }
            else
            {
                sqlWhere = sqllist.ToSql() + " and " + sqlWhere;
            }
            dtTbBstDirectorLetter = Q.GetRecordByPage("ID,LSH,CONTENT,VREPLYSIGN,CREATEDATE", sqlWhere, "CREATEDATE", intPageSize, intPageIndex, TbBstDirectorLetterConst.QTableName, TbBstDirectorLetterConst.FieldKey, "desc").Tables[0];
            if (dtTbBstDirectorLetter != null && dtTbBstDirectorLetter.Rows.Count > 0)
            {
                for (int i = 0; i < dtTbBstDirectorLetter.Rows.Count; i++)
                {
                    var color = "";
                    if (dtTbBstDirectorLetter.Rows[i]["VREPLYSIGN"].ToString() == "未回复")
                    {
                        color = "FF0000";
                    }
                    else if (dtTbBstDirectorLetter.Rows[i]["VREPLYSIGN"].ToString() == "已推送")
                    {
                        color = "326AC9";
                    }
                    else
                    {
                        color = "32C904";
                    }
                    dtTbBstDirectorLetter.Rows[i]["VREPLYSIGN"] = "<span style=\"color:#" + color + "\">" + dtTbBstDirectorLetter.Rows[i]["VREPLYSIGN"] + "</span>";
                    if (dtTbBstDirectorLetter.Rows[i]["CONTENT"].ToString().Length > 61)
                    {
                        dtTbBstDirectorLetter.Rows[i]["CONTENT"] = dtTbBstDirectorLetter.Rows[i]["CONTENT"].ToString().Substring(0, 60) + "...";
                    }
                }
            }
            if (dtTbBstDirectorLetter != null && dtTbBstDirectorLetter.Rows.Count > 0)
            {
                for (int i = 0; i < dtTbBstDirectorLetter.Columns.Count; i++)
                {
                    hm = new HearderMessage();
                    hm.name = dtTbBstDirectorLetter.Columns[i].Caption;
                    list.Add(hm);
                }
                tm.Header = list;
                tm.data = dtTbBstDirectorLetter;
                tm.totalCount = Convert.ToString((int)Q.RowCount);
            }
            //for (int j = 0; j < dtTbBstDirectorLetter.Rows.Count; j++)
            //{
            //    for (int m = 1; m < 3; m++)
            //    {
            //        string decode = dtTbBstDirectorLetter.Rows[j][m].ToString();
            //        dtTbBstDirectorLetter.Rows[j][m] = DES.Decode(decode);
            //    }
            //}
            IsoDateTimeConverter dtConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
            string json = JsonConvert.SerializeObject(tm, dtConverter);
            context.Response.Write(json);
        }
        #endregion

        #region 回复记录
        /// <summary>
        /// 回复记录
        /// </summary>
        protected void ReplyRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            //var model = new TbMsjwSqjg();
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            TbBstDirectorLetter mTbBstDirectorLetter = new TbBstDirectorLetter();
            TbMsjwSqjg mTbMsjwSqjg = new TbMsjwSqjg();
            string paramKey = context.Request.Params["id"];
            try
            {
                if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                mTbBstDirectorLetter = TbBstDirectorLetterBLL.Load(paramKey); //根据键值获取实体信息
                var guid = mTbBstDirectorLetter.Id;
                var list = TbMsjwSqjgBLL.SelectList(guid);
                if (list.Count > 0)
                {
                    if (list.Count == 1)
                    {
                        mTbMsjwSqjg = list.SingleOrDefault();
                    }
                    else if (list.Count > 1)
                    {
                        var count = list.Where(a => a.Id > 0).Count();
                        if (count > 0)
                        {
                            mTbMsjwSqjg = list.FirstOrDefault(a => a.Id > 0);
                        }
                        else
                        {
                            mTbMsjwSqjg = list.OrderByDescending(a => a.ZbBlrq).FirstOrDefault();
                        }
                    }
                }
                else
                {
                    mTbMsjwSqjg = null;
                }



                #region 根据id取回复时间、回复人 回复内容
                //var guid = mTbBstDirectorLetter.Id;
                //try
                //{
                //    QueryByPage Q = new QueryByPage();
                //    DataSet dt = Q.GetRecordByPage("*", " where gdid='" + guid + "' ", "", 2, 1, "tb_msjw_sqjg", "id", "");
                //    if (dt.Tables[0].Rows.Count > 0)
                //    {
                //        for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
                //        {
                //            if (dt.Tables[0].Rows[i]["ID"].ToString() != "0")
                //            {
                //                mTbMsjwSqjg.ZbBljg = dt.Tables[0].Rows[i]["ZB_BLJG"].ToString();
                //                mTbMsjwSqjg.ZbBlrxm = dt.Tables[0].Rows[i]["ZB_BLRXM"].ToString();
                //                mTbMsjwSqjg.ZbBlrq = Convert.ToDateTime(dt.Tables[0].Rows[i]["ZB_BLRQ"]);
                //                mTbMsjwSqjg.Id = Convert.ToDecimal(dt.Tables[0].Rows[i]["ID"]);
                //                mTbMsjwSqjg.JbTsxs = Convert.ToDecimal(dt.Tables[0].Rows[i]["JB_TSXS"]);
                //                mTbMsjwSqjg.ZbBlrlxfs = dt.Tables[0].Rows[i]["ZB_BLRLXFS"].ToString();
                //                mTbMsjwSqjg.Pkid = dt.Tables[0].Rows[i]["PKID"].ToString();
                //            }
                //            else
                //            {
                //                mTbMsjwSqjg.ZbBljg = dt.Tables[0].Rows[i]["ZB_BLJG"].ToString();
                //                mTbMsjwSqjg.ZbBlrxm = dt.Tables[0].Rows[i]["ZB_BLRXM"].ToString();
                //                mTbMsjwSqjg.ZbBlrq = Convert.ToDateTime(dt.Tables[0].Rows[i]["ZB_BLRQ"]);
                //                mTbMsjwSqjg.Id = Convert.ToDecimal(dt.Tables[0].Rows[i]["ID"]);
                //                mTbMsjwSqjg.JbTsxs = Convert.ToDecimal(dt.Tables[0].Rows[i]["JB_TSXS"]);
                //                mTbMsjwSqjg.ZbBlrlxfs = dt.Tables[0].Rows[i]["ZB_BLRLXFS"].ToString();
                //                mTbMsjwSqjg.Pkid = dt.Tables[0].Rows[i]["PKID"].ToString();
                //            }
                //        }
                //    }
                //}
                //catch (Exception e) { }
                #endregion

                // mTbMsjwSqjg = TbMsjwSqjgBLL.Load(paramKey);//仅 有1条
                if (mTbMsjwSqjg != null)////有回复就是修改
                {
                    //对Session的处理
                    var mUser = AppOrganizatiOnUserBLL.Load(context.Session["UserID"].ToString());
                    var mOrg = AppOrganizatiOnBLL.Load(mUser.OrgnaId);
                    mTbMsjwSqjg.ZbBlrq = DateTime.Now; //回复时间
                    mTbMsjwSqjg.ZbBlrxm = mUser.UserName; //回复人
                    mTbMsjwSqjg.JbTsxs = 320; //回复人单位 ////回复类别，局长信箱是320代码
                    mTbMsjwSqjg.Gdid = mTbBstDirectorLetter.Id; //恢复表主键，存放诉求表的id
                    mTbMsjwSqjg.ZbBljg = context.Request.Form["texReplycontent"]; //回复内容
                    //mTbMsjwSqjg.Movesign = "2";

                    mResultModel = TbMsjwSqjgBLL.Update(mTbMsjwSqjg, context.Session["UserID"], true); //编辑操作
                }
                else////无回复就是新增
                {
                    TbMsjwSqjg mTbMsjwSqjgAdd = new TbMsjwSqjg();
                    var mUser = AppOrganizatiOnUserBLL.Load(context.Session["UserID"].ToString());
                    var mOrg = AppOrganizatiOnBLL.Load(mUser.OrgnaId);
                    mTbMsjwSqjgAdd.Pkid = Guid.NewGuid().ToString();
                    mTbMsjwSqjgAdd.ZbBlrq = DateTime.Now; //回复时间
                    mTbMsjwSqjgAdd.ZbBlrxm = mUser.UserName; //回复人
                    mTbMsjwSqjgAdd.JbTsxs = 330; //回复人单位 ////回复类别，诉求回复是330代码
                    mTbMsjwSqjgAdd.Gdid = mTbBstDirectorLetter.Id; //恢复表主键，存放诉求表的id
                    mTbMsjwSqjgAdd.ZbBljg = context.Request.Form["texReplycontent"]; //回复内容
                    //mTbMsjwSqjgAdd.Movesign = "2";
                    mResultModel = TbMsjwSqjgBLL.Insert(mTbMsjwSqjgAdd, context.Session["UserID"], true); //新建操作
                }
                if (mResultModel.ISSucceed)
                {
                    ResultModel mResultModelNew = new ResultModel();
                    //mTbBstDirectorLetter.Movesign = "2";
                    mTbBstDirectorLetter.Replysign = "1";
                    mResultModelNew = TbBstDirectorLetterBLL.Update(mTbBstDirectorLetter, context.Session["UserID"], true); //新建操作
                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 推送记录
        /// <summary>
        /// 推送记录
        /// </summary>
        protected void PushRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            TbBstDirectorLetter mTbBstDirectorLetter = new TbBstDirectorLetter();

            string paramKey = context.Request.Params["id"];
            try
            {

                if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                mTbBstDirectorLetter = TbBstDirectorLetterBLL.Load(paramKey); //根据键值获取实体信息
                if (mTbBstDirectorLetter != null)
                {
                    mTbBstDirectorLetter.Movesign = "0"; //内容
                    mTbBstDirectorLetter.Replysign = "2";
                    mResultModel = TbBstDirectorLetterBLL.Update(mTbBstDirectorLetter, context.Session["UserID"], true); //新建操作

                }
                else
                {
                    mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                    mResultModel.ISSucceed = false;

                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 批量推送记录
        /// <summary>
        /// 批量推送记录
        /// </summary>
        protected void PushRecords()
        {

            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            try
            {
                string[] arryParamKey = context.Request.Params["id"].ToString().Split(',');
                if (arryParamKey.Length == 0)
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                foreach (var paramKey in arryParamKey)
                {
                    var mTbBstDirectorLetter = TbBstDirectorLetterBLL.Load(paramKey); //根据键值获取管理员
                    if (mTbBstDirectorLetter.Replysign == "1")
                    {
                        // 添加警告框提示：已回复不能推送！
                        mResultModel.ErrorCode = -997;
                    }

                    else
                    {
                        mTbBstDirectorLetter.Movesign = "0";
                        mTbBstDirectorLetter.Replysign = "2";
                        mResultModel = TbBstDirectorLetterBLL.Update(mTbBstDirectorLetter, context.Session["UserID"], true); //新建操作
                    }
                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); ; //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, ""); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }

        }
        #endregion

    }
}


